import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 09 - 04
 * Time: 22:16
 */
//牛客 数组中只出现一次的两个数字
public class Solution3 {
    //法一 官方推荐方法
    public static int[] FindNumsAppearOnce (int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if(map.containsKey(nums[i])) {
                map.put(nums[i], map.get(nums[i]) + 1);
            }else {
                map.put(nums[i], 1);
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if(map.get(nums[i]) == 1) {
                arrayList.add(nums[i]);
            }
        }
        if(arrayList.get(0) < arrayList.get(1)) {
            return new int[]{arrayList.get(0), arrayList.get(1)};
        }else {
            return new int[]{arrayList.get(1), arrayList.get(0)};
        }
    }
}
